package ntu.metaweb.storage;


public class Comment extends Contribution {
  /**
	 * 
	 */
	private static final long serialVersionUID = 7875449267916213646L;
	
	// unique per page
	private int id;
	private String text;
  private int parentId;
  
	public Comment(String contributor, String text) {
		this(contributor, text, -1);
	}
	
	public Comment(String contributor, String text, int parentId) {
		this.contributors.add(contributor);
		this.id = -1;
		this.text = text;
		this.parentId = parentId;
	}

	@Override
	public void addRating(String rater, int rating) {
		if (this.rating.containsKey(rater)) {
			this.rating.get(rater).setRating(rating);
		} else {
			this.rating.put(rater, new BinaryRating(rater, rating));
		}
	}
	
	public int getId() {
		return this.id;
	}
	
	public String getText() {
		return this.text;
	}
	
	public int getParentId() {
		return this.parentId;
	}
	
	@Override
	public int hashCode() {
		return this.id;
	}
	
	@Override
	public boolean equals(Object o) {
		if (!(o instanceof Comment)) {
			return false;
		}
		
		Comment comment = (Comment) o;
		return this.id == comment.id;
	}

	void setId(int i) {
		this.id = i;
	}
}
